//
//  AQTaskCopyAndStrong.m
//  RunLoopDemo
//
//  Created by zhangjikuan on 2020/8/27.
//  Copyright © 2020 hsgd. All rights reserved.
//

#import "AQTaskCopyAndStrong.h"
#import "Person.h"
#import <UIKit/UIKit.h>
@implementation AQTaskCopyAndStrong

- (void)execute {
    
    NSMutableString *result = [NSMutableString string];
    
    Person *p = [[Person alloc] init];
    
    NSMutableString *string = [@"huangfeng" mutableCopy];
    NSLog(@"内存地址 --> %p", string);
    
    [result appendFormat:@"内存地址 --> %p", string];
    [result appendString:@"\n"];
    
    p.idNumber = string;
    p.name = string;
    NSLog(@"idNumber %@", p.idNumber);
    NSLog(@"name %@", p.name);
    
    [result appendFormat:@"idNumber %@", p.idNumber];
    [result appendString:@"\n"];
    [result appendFormat:@"name %@", p.name];
    [result appendString:@"\n"];
      
    
    // 观察赋值以后的内存变化
    NSLog(@"idNumber对象的内存地址-->%p ", p.idNumber);
    NSLog(@"name对象的内存地址-->%p", p.name);
    
    [string appendString:@"+"];

    
    NSLog(@"idNumber %@", p.idNumber); // idNumber huangfeng
    NSLog(@"name %@", p.name); // name huangfeng+
    

    string = [@"second" mutableCopy];
    NSLog(@"idNumber %@", p.idNumber);
    NSLog(@"name %@", p.name);
    [result appendFormat:@"idNumber %@", p.idNumber];
    [result appendString:@"\n"];
    [result appendFormat:@"name %@", p.name];
    [result appendString:@"\n"];
    
    NSLog(@"idNumber对象的内存地址-->%p ", p.idNumber);
    NSLog(@"name对象的内存地址-->%p", p.name);
    
    NSMutableArray *list = [NSMutableArray arrayWithObjects:@"数学",@"计算机",@"概率论", nil];
    p.interests = list;
    p.subjects = list;
    NSLog(@"strong 修饰 p.interests = = = %@",p.interests);
    NSLog(@"copy 修饰 p.subjects = = = %@",p.subjects);

    [list addObject:@"数据结构与算法"];
    NSLog(@"strong 修饰 p.interests = = = %@",p.interests);
    NSLog(@"copy 修饰 p.subjects = = = %@",p.subjects);
    
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:@"dict for copy and strong" forKey:@"test"];
    p.dic1 = dict;
    p.dic2 = dict;
    NSLog(@"strong 修饰 p.dic1 = = = %@",p.dic1);
    NSLog(@"copy 修饰 p.dic2 = = = %@",p.dic2);
    [dict setValue:@"Life is a practice " forKey:@"life"];
    NSLog(@"strong 修饰 p.dic1 = = = %@",p.dic1);
    NSLog(@"copy 修饰 p.dic2 = = = %@",p.dic2);
    
    // 属性使用 可变数据类型时
    
    NSMutableArray *muList = [NSMutableArray arrayWithObjects:@"数学",@"计算机",@"概率论", nil];

    p.musubjects = muList;
    p.muInterests = muList;
    NSLog(@"strong muInterests %@", p.muInterests);
    NSLog(@"copy musubjects %@", p.musubjects);

    [muList addObject:@"算法导论"];
    [muList addObject:@"English"];
    
    NSLog(@"strong muInterests %@", p.muInterests);
    NSLog(@"copy musubjects %@", p.musubjects);
    
    
 
}

- (void)executeBy:(id)target {
    [self execute];
}
@end
